import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/module/record/data_logic.dart';
import 'package:ball_lion/utils/mode_config.dart';
import 'package:ball_lion/widgets/loading/loading_widget.dart';

import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/resources/styles.dart';
import 'package:ball_lion/utils/utils.dart';

class DataPage extends StatefulWidget {
  const DataPage({super.key});

  @override
  State<DataPage> createState() => _DataPageState();
}

class _DataPageState extends State<DataPage> {
  @override
  Widget build(BuildContext context) {
    final DataLogic logic = Get.put(DataLogic());

    return GetBuilder<DataLogic>(builder: (logic) {
      return LoadingWidget<bool>(
        isLoading: false,
        data: false,
        reconnect: logic.getRefresh,
        child: () => Scaffold(
          body: Container(
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                  colors: [Colours.white, Colours.greyF2F3F7],
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  stops: [0.2, 0.4]),
            ),
            child: Stack(
              alignment: Alignment.topCenter,
              children: [
                Image.asset(Utils.getImgPath("nav_head_back.png"),
                    width: Get.width, height: Get.width * 128 / 375),
                Column(
                  children: [
                    AppBar(
                      backgroundColor: Colours.transparent,
                      title: Styles.tabbar(
                          tabs: [
                            if (ModeConfig.ai)
                              Image.asset(
                                logic.index == 0
                                    ? Utils.getImgPath("ai_choose.png")
                                    : Utils.getImgPath("ai_unchoose.png"),
                                width: 68,
                                height: 44,
                              ),
                            Image.asset(
                                logic.index == (ModeConfig.ai ? 1 : 0)
                                    ? Utils.getImgPath("record_choose.png")
                                    : Utils.getImgPath("record_unchoose.png"),
                                width: 68,
                                height: 44),
                          ],
                          controller: logic.tabController,
                          scrollable: true,
                          labelPadding:
                              const EdgeInsets.symmetric(horizontal: 6),
                          indicatorBottom: 6,
                          labelColor: Colours.white,
                          unselectedLabelColor: Colours.white,
                          onTap: (index) => Utils.onEvent("data_tab",
                              params: {"tab": index})),
                    ),
                    Expanded(
                      child: ExtendedTabBarView(
                          controller: logic.tabController,
                          children: logic.page),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      );
    });
  }
}
